package logic

import (
	"context"

	"shorturl/rpc/transform/internal/svc"
	"shorturl/rpc/transform/transform"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserListLogic {
	return &UserListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserListLogic) UserList(in *transform.UserListReq) (*transform.UserListResp, error) {
	// todo: add your logic here and delete this line
	resp, err := l.svcCtx.Model.List(l.ctx, int(in.Page), 10)
	if err != nil {
		return nil, err
	}

	var user []*transform.UserProto
	for _, item := range resp {
		userProto := transform.UserProto{
			UserName:       item.UserName.String,
			Nickname:       item.Nickname.String,
			TelphoneNumber: item.TelphoneNumber.String,
			Email:          item.Email.String,
			Department:     item.Department.String,
			Role:           item.Role.String,
			State:          item.State.Bool,
			Id:             item.Id,
		}
		user = append(user, &userProto)
	}

	return &transform.UserListResp{
		Users: user,
	}, nil
}

// func _map[S ~[]E, E any, M any](s S, f func(E) M) []*M {
// 	var resp []*M
// 	for _, item := range s {
// 		mapedValue := f(item)
// 		slices.Insert(resp, 1, &mapedValue)
// 	}
// 	return resp

// }

// func ContainsFunc[S ~[]E, E any](s S, f func(E) bool) bool
